package cn.jinjimi.framework.pay;

import android.app.Activity;

import java.lang.ref.WeakReference;

/**
 *
 * @author Jinsen
 * @date 2015/7/6
 */
public abstract class AbstractPayTask implements IPay {
    private IPayResultCallback mPayResultCallback;
    private WeakReference<Activity> mActivityRef;

    public AbstractPayTask(Activity activity){
        mActivityRef = new WeakReference<>(activity);
    }

    protected Activity getContext() {
        if (mActivityRef != null) {
            return mActivityRef.get();
        }
        return null;
    }


    /**
     * 返回支付名称
     * @return
     */
    public abstract String getName();

    /**
     * 返回支付代码
     * @return
     */
    public abstract String getCode();

    public void setPayResultCallback(IPayResultCallback callback) {
        mPayResultCallback = callback;
    }

    /**
     * 支付结果回调
     * @param result
     */
    protected void onResult(PayResult result){
        if(mPayResultCallback !=null){
            mPayResultCallback.onResult(result);
        }
    }


}
